package me.kennylee.mobile.sms.code;

import me.kennylee.mobile.sms.cache.SmsCodeCacheKey;

import java.util.Map;

/**
 * <p> 验证码发送的工具类 </p>
 * <p>Created on 2/2/2018.</p>
 *
 * @author kennylee
 */
public class AlidayuVerifyCodeSender extends VerifyCodeSender {

    /**
     * 模板代码
     */
    protected String templateCode;
    /**
     * 签名
     */
    protected String signName;
    /**
     * 手机发送累加器
     */
    protected static String mobileSmsCountCacheName = SmsCodeCacheKey.getMobileSmsCount();
    /**
     * <p>短信发送间隔</p>
     */
    protected static String smsIntervalCacheName = SmsCodeCacheKey.getSmsInterval();
    /**
     * 验证码有效时间
     */
    protected static String codeLiveCacheName = SmsCodeCacheKey.getSmsCodeLive();

    AlidayuVerifyCodeSender(String apiKey, String apiSecret) {
        super(apiKey, apiSecret);
    }

    @Override
    protected SmsSender getSmsSender() {
        return SmsFactory.of(SmsApiType.ALIDAYU, apiKey, apiSecret);
    }

    @Override
    protected SmsMessage getSmsMessage(String mobile, Map<String, String> params) {
        return createSmsMessage(mobile, params, templateCode, signName);
    }

    @Override
    protected String getMobileSmsCountCacheName() {
        return mobileSmsCountCacheName;
    }

    @Override
    protected String getSmsIntervalCacheName() {
        return smsIntervalCacheName;
    }

    @Override
    protected String getCodeLiveCacheName() {
        return codeLiveCacheName;
    }

    public static AlidayuVerifyCodeSender of(String apiKey, String apiSecret, String templateCode, String signName) {
        AlidayuVerifyCodeSender o = new AlidayuVerifyCodeSender(apiKey, apiSecret);
        o.templateCode = templateCode;
        o.signName = signName;
        return o;
    }
}
